package com.nuc.crp5;

/**
 * Time    : 2023/3/23 22:03
 * Author  : 王摇摆
 * FileName: Main1.java
 * Software: IntelliJ IDEA 2020.2.2
 * Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
 */

/**
 * 实现接口后
 * 针对不同的行为做具体的泛化实现
 * 用关联（聚合）的方式代替继承
 * <p>
 * 合成复用原则：尽量使用组合/聚合的方式，而不是使用继承。
 */
public class Main5 {
    public static void main(String[] args) {
        MallarDuck mallarDuck = new MallarDuck("MallarDuck");
        mallarDuck.setQuackable(new Quack());
        mallarDuck.setFlyable(new FlyWithWings());

        mallarDuck.display();
        mallarDuck.swim();
        mallarDuck.quack();
        mallarDuck.fly();
        System.out.println("--------------------------");

        RedaheadDuck redaheadDuck = new RedaheadDuck("RedaheadDuck");
        redaheadDuck.setQuackBehavior(new Quack());
        redaheadDuck.setFlyBehavior(new FlyWithWings());

        redaheadDuck.display();
        redaheadDuck.swim();
        redaheadDuck.quack();
        redaheadDuck.fly();
        System.out.println("--------------------------");

        RubberDuck rubberDuck = new RubberDuck("RubberDuck");
        rubberDuck.setQuackBehavior(new Squeak());
        rubberDuck.setFlyBehavior(new FlyNoWay());

        rubberDuck.display();
        rubberDuck.swim();
        rubberDuck.quack();
        rubberDuck.fly();
        System.out.println("--------------------------");

        DecoyDuck decoyDuck = new DecoyDuck("DecoyDuck");
        decoyDuck.setQuackBehavior(new MuteQuack());
        decoyDuck.setFlyaBehavior(new FlyNoWay());

        decoyDuck.display();
        decoyDuck.swim();
        decoyDuck.quack();
        decoyDuck.fly();
        System.out.println("--------------------------");
    }
}
